package com.study.nvr.web;

import com.study.nvr.bean.CmdTasker;
import com.study.nvr.service.NvrService;
import com.study.r.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import nvr.utils.commandManager.CommandManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author study
 * @version 1.0
 * @date 2020/6/15 23:25
 */
@Slf4j
@RestController
@RequestMapping("nvr")
@Api(tags = "ffmpeg 测试")
public class NvrController {

    @Autowired
    NvrService nvrService;
    @Autowired
    CommandManager commandManager;

    @ApiOperation("屏幕录制")
    @GetMapping("screen")
    public R screen() {
        String snapPath = nvrService.screen();
        return R.ok().data("screen", snapPath);
    }

    @ApiOperation("屏幕截图")
    @GetMapping("snap")
    public R snap() {
        String snapPath = nvrService.snap();
        return R.ok().data("snap", snapPath);
    }

    @ApiOperation("任务查询")
    @GetMapping("tasks")
    public R<List<CmdTasker>> task() {
        List<CmdTasker> tasks = nvrService.getTasks();
        return R.ok().result(tasks);
    }

    @ApiOperation("停止全部")
    @GetMapping("stops")
    public R stopAll() {
        int i = commandManager.stopAll();
        return R.ok().data("nums", i);
    }

}
